
package com.phm.phmneuron.connection;

import com.phm.phmneuron.neuron.Neuron;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;

/**
 *
 * @author PARHAM
 */
public class ConnectionsContainer extends HashSet<Connection> {

    public boolean add (Neuron n1, Neuron n2) {
        return add (n1, n2, 0);
    }
    public boolean add (Neuron n1, Neuron n2, float edge) {
        return add (new Connection(n1, n2, edge));
    }
    public boolean remove (Neuron n1, Neuron n2) {
        return remove (new Connection(n1, n2));
    }
    public boolean contains (Neuron n1, Neuron n2) {
        return contains (new Connection(n1, n2));
    }
    public List<Neuron> getNeighbors (Neuron n) {
        LinkedList<Neuron> neighbors = new LinkedList<>();
        for (Connection x : this) {
            Neuron temp = x.connectTo(n);
            if (temp != null) {
                neighbors.add(n);
            }
        }
        
        return neighbors;
    }
    public boolean setConnectionEdgeValue (Connection c, float edge) {
        for (Connection x : this) {
            if (c.equals(x)) {
                c.edgeValue = edge;
                return true;
            }
        }
        return false;
    }
    public boolean incrementConnectionEdgeValue (Connection c) {
        for (Connection x : this) {
            if (c.equals(x)) {
                c.edgeValue++;
                return true;
            }
        }
        return false;
    }
    public void incerementConnectionsEdgeValue () {
        for (Connection x : this) {
            x.edgeValue++;
        }
    }
}
